package com.ymx.darling.util;

import java.util.Collection;
import java.util.Objects;
import java.util.StringJoiner;

public class CollectionUtil {
    /**
     * 返回collection实例数据的字符串表现形式 例如(1,2,3)
     * @param collection 实例
     * @return String
     */
    public static String toString(Collection<?> collection) {
        if (collection == null || collection.isEmpty()) {
            return "()"; // 处理空集合的情况
        }
        StringJoiner joiner = new StringJoiner(", ", "(", ")");
        collection.forEach(item -> joiner.add(item.toString()));
        return joiner.toString();
    }

    public static boolean notEmpty(Collection<?> collection) {
        return Objects.nonNull(collection) && !collection.isEmpty();
    }

    public static boolean isEmpty(Collection<?> collection) {
        return Objects.isNull(collection) || collection.isEmpty();
    }

    public static boolean isCollectionType(Class<?> paramType) {
        return paramType != null && Collection.class.isAssignableFrom(paramType);
    }
}
